package mvp.com.bbc.rcjavaretrofitdaggermvp.mvp.activity;

import android.view.View;
import android.webkit.WebChromeClient;
import android.webkit.WebSettings;
import android.webkit.WebView;
import android.webkit.WebViewClient;
import android.widget.LinearLayout;

import butterknife.BindView;
import mvp.com.bbc.rcjavaretrofitdaggermvp.R;
import mvp.com.bbc.rcjavaretrofitdaggermvp.app.utils.ShareUtils;
import mvp.com.bbc.rcjavaretrofitdaggermvp.baseAF.BaseActivity;

/**
 * Created by ${cbf} on 2017/11/27.
 * 每一个新闻的详情界面
 */

public class NewsDetailActivity extends BaseActivity {
    @BindView(R.id.title)
    LinearLayout titleBarCorner;
    @BindView(R.id.webview)
    WebView webView;


    @Override
    protected int setContentLayout() {
        return R.layout.activity_home_page_detail;
    }

    @Override
    protected void findViews() {

    }

    @Override
    protected void init() {
        initTitleBar(titleBarCorner, "新闻详情", true, new String[]{"分享"});
        final String url = getIntent().getStringExtra("url");
        WebSettings webSettings = webView.getSettings();
        webSettings.setJavaScriptEnabled(true);
        webSettings.setUseWideViewPort(true);
        webSettings.setDefaultTextEncodingName("utf-8");//设置字符集
        webSettings.setLoadWithOverviewMode(true);
        webSettings.setLoadWithOverviewMode(true);//设置网页缩放至手机大小
        webSettings.setUseWideViewPort(true);
        webView.getSettings().setJavaScriptEnabled(true);//让webview支持javascript
        webView.setWebChromeClient(new WebChromeClient());//支持特殊javascript
        webView.loadUrl(url);
        webView.setWebViewClient(new MyWebViewClient());
        layouts.get(0).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                ShareUtils.shareWeb(NewsDetailActivity.this, url, "新闻", "11111111");
            }
        });
    }

    private class MyWebViewClient extends WebViewClient {
        @Override
        // 在WebView中而不在默认浏览器中显示页面
        public boolean shouldOverrideUrlLoading(WebView view, String url) {
            view.loadUrl(url);
            return true;
        }

    }

    @Override
    protected void setListeners() {
    }

    @Override
    public void onClick(View view) {

    }
}
